/**
 * 广告滚动栏管理初始化
 */
var Advertisement = {
    id: "AdvertisementTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Advertisement.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', align: 'center', valign: 'middle',width:'50px'},
        {title: '广告栏', field: 'advert', align: 'center', valign: 'middle', sortable: true},
        {title: '滚动条', field: 'scrollbar', align: 'center', valign: 'middle', sortable: true},
        {title: '创建时间', field: 'create_time', align: 'center', valign: 'middle', sortable: true},
        {title: '更新时间', field: 'update_time', align: 'center', valign: 'middle', sortable: true},
        {title: '状态', field: 'state_name', align: 'center', valign: 'middle', sortable: true}];
};

/**
 * 检查是否选中
 */
Advertisement.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Advertisement.seItem = selected[0];
        return true;
    }
};
/**
 * 点击添加
 */
Advertisement.openAdd = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['500px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/advertisement/advertisement_add'
    });
    this.layerIndex = index;
};

/**
 * 编辑
 */
Advertisement.openChange = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改',
            area: ['500px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/advertisement/advertisement_update/' + Advertisement.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
Advertisement.del = function () {
    if (this.check()) {

        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/advertisement/delete", function () {
                Feng.success("删除成功!");
                Advertisement.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id",Advertisement.seItem.id);
            ajax.start();
        };

        Feng.confirm("是否刪除?", operation);
    }
};

/**
 * 查询列表
 */
Advertisement.search = function () {
    var queryData = {};
    queryData['type'] = $("#type").val();
    Advertisement.table.refresh({query: queryData});
};

Advertisement.resetSearch = function () {
    $("#type").val("");

    Advertisement.search();
}

$(function () {
     var defaultColunms = Advertisement.initColumn();
        var table = new BSTable("AdvertisementTable", "/advertisement/list", defaultColunms);
        table.setPaginationType("client");
        Advertisement.table = table.init();
});
